//////////////////////////////////
//
// PWM configuration
//
//////////////////////////////////

#include "p18f26k22.h"
#include <GenericTypeDefs.h>
#include "pwm.h"


void pwm_init(void)
{    
    CLK_TRIS            = 0b1;      //Set TRIS OFF
    CCP2CONbits.CCP2M   = 0b0000;   //OFF

    //TMR1 config
    PIR1bits.TMR1IF     = 0b0;      //clear interrupt flag
    PIE1bits.TMR1IE     = 0b1;      //Enable interrupt
    IPR1bits.TMR1IP     = 0b1;      //High priority

    //TMR1 timing config
      TMR1L           = 0x82;        // 0xFFFF - 0x7D (1000) = 0xFF82
      TMR1H           = 0xFF;        //reset

    T1CONbits.TMR1CS    = 0b00;     //Fosc/4 Fosc = 64M
    T1CONbits.T1RD16    = 0b1;      //16bit mode
    T1CONbits.T1CKPS    = 0b11;     //1:8 Pre-scaler (post scaler only relevent to TxIF


    //T1 enable
    T1CONbits.TMR1ON    = 0b1;      //Switch Timer 2 ON
    CLK_TRIS            = 0b0;      //Set TRIS to OP
    BIT_LOAD_TRIS       = 0b0;      //Set TRIS to OP
    /* MkII board */
    M_RESET_TRIS        = 0b0;      //Set TRIS to OP
    /* MkII board */


}

